import oracle from "../oracle";

export default function NewFlow(): void {
    //每週二將上週已經簽核完成的任務重新啟動，插入一條新的流程。
    let sql = " declare record_week varchar2(7);"
    sql +=" begin"
    sql += " select TO_CHAR(SYSDATE, 'YYYY') || '-' ||TO_CHAR(SYSDATE, 'IW') into record_week from dual ;"
    sql += " for r1 in (select * from xx_cf_customar_apply_header"
    sql += " where current_flow = 10 and status = 'Open' and action_klm = 'xdomain\\cf168cqe')"
    sql += " loop"
    sql += " if r1.week_record <> record_week then"
    sql += " insert into xx_cf_customar_apply_flow values (r1.docid,10,'Information Maintaince','xdomain\\cf168cqe','',''"
    sql += " ,'system',sysdate,(TO_CHAR(SYSDATE, 'YYYY') || '-' ||TO_CHAR(SYSDATE, 'IW')));"
    sql += " update xx_cf_customar_apply_header set week_record = TO_CHAR(SYSDATE, 'YYYY') || '-' ||TO_CHAR(SYSDATE, 'IW')"
    sql += " where docid = r1.docid;"
    sql += " end if;"
    sql += " end loop;"
    sql += " end;"
    oracle.connChaosTest({sql})
  }
  